using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Lottery.App.DAL;
using Lottery.App.Model;
using Lottery.App.Core;
using NUnit.Framework;

namespace Lottery.App.Test
{
    [TestFixture]
    public class Tool
    {
        private class Nested
        {
            public IList<Record> Table;
        }

        private class Record
        {
            public string IssueNum { get; set; }

            public string Result { get; set; }
        }

        public void GetHistoryData()
        {
            const string URL = "http://www.310win.com/Info/Result/High.aspx?load=ajax&typeID=115&date=";

            IList<Record> list = null;
            RecordDao dao = new RecordDao();
            WebUtils web = new WebUtils();

            DateTime day = new DateTime(2012, 5, 16);
            for (int i = 0; i < 238; i++)
            {
                list = JsonConvert.DeserializeObject<Nested>(
                            web.DoGet(String.Format("{0}{1:yyyy-MM-dd}", URL, day), null)
                       ).Table;

                string date = day.ToString("yyyyMMdd");

                dao.BeginTransaction();
                for (int j = 83; j >= 0; j--)
                {
                    dao.Save(new RecordInfo(date, 84 - j, list[j].Result));
                }
                dao.CommitTransaction();

                day = day.AddDays(1);
            }
        }


    }
}
